ActiveAdmin.register AlertRecord do

  menu label: '告警记录', priority: 3

  actions :index, :show

  index do
    column :alert_time
    column '规则' do |record|
      record.alert_rule.name if record.alert_rule
    end
    column :current_price
    column '触发条件' do |record|
      "#{record.alert_rule.condition} #{record.alert_rule.threshold}" rescue ''
    end
    column :status do |r|
      status_tag(r.status, class: r.status == 'sent' ? :green : :grey)
    end
    column :message
  end

  filter :alert_rule
  filter :alert_time
  filter :status, as: :select

  show do
    attributes_table do
      row :id
      row :name
      row :alert_rule
      row :alert_time
      row :current_price
      row :status
      row :message
      row :created_at
      row :updated_at
    end
  end
end
